﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCM.UI.ChildWindows
{
    public partial class TeamMaterialMonthPlan : EFViewCmes
    {
        public TeamMaterialMonthPlan(String dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="type"></param>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    base.Mode = OperationMode.Update;
                    this.fdPlanType.IsEnabled = false;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            if (this.fdHistoryDetail.Visibility == Visibility.Visible)
            {
                this.fdHistory.Value += this.fdHistoryDetail.Value.ToString();
            }
            base.OnCommitButtonClick("ZMCM22", sender, e);
        }

        /// <summary>
        /// 确定前的申请日期校验
        /// </summary>
        /// <returns></returns>
        //public override bool ThisValidateField()
        //{
        //    if (this.fdApplicationDate.Value != null)
        //    {
        //        string[] ApplicationDate = this.fdApplicationDate.Value.ToString().Split('-');
        //        if (validateDate(ApplicationDate) == false)
        //        {
        //            return false;
        //        }
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //}

        /// <summary>
        /// 保证时间在计划月份内
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        //private bool validateDate(string[] date)
        //{
        //    if (int.Parse(this.fdYear.Value.ToString()) != int.Parse(date[0]))
        //    {
        //        base.OpenEFWindowAlert("所选择的日期年份不是计划年份，请重新选择年份！", true);
        //        return false;
        //    }
        //    if (int.Parse(this.fdMonth.Value.ToString()) < int.Parse(date[1]))
        //    {
        //        base.OpenEFWindowAlert("所选择的申请日期月份不能大于计划月份，请重新选择月份！", true);
        //        return false;
        //    }
        //    return true;
        //}

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }
    
    
    
    
    
    }
}
